package com.valentinalee.bms.web.listener;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.valentinalee.bms.entity.PublisherVO;
import com.valentinalee.bms.entity.TypeVO;
import com.valentinalee.bms.service.PublisherService;
import com.valentinalee.bms.service.TypeService;
import com.valentinalee.bms.service.impl.PublisherServiceImpl;
import com.valentinalee.bms.service.impl.TypeServiceImpl;

public class ApplicationListener implements ServletContextListener {

	public void contextDestroyed(ServletContextEvent event) {
	}

	public void contextInitialized(ServletContextEvent event) {
		System.out.println("web应用的启动开始初始化!!!!!!!!!!!");

		try {
			PublisherService publisherService = new PublisherServiceImpl();
			List<PublisherVO> pulishers = publisherService.queryPublisher();
			TypeService typeService = new TypeServiceImpl();
			List<TypeVO> types = typeService.queryType();
			ServletContext sc = event.getServletContext();
			sc.setAttribute("BOOK-PUBLISHERS", pulishers);
			sc.setAttribute("BOOK-TYPES", types);
		} catch (Exception e) {
				e.printStackTrace();
			// throw new ThisAppException("加载书籍类型发生异常");
		}

	}

}
